package com.egg.ylt.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.egg.ylt.R;
import com.egg.ylt.Utils.Constants;
import com.egg.ylt.Utils.CustomUtils;
import com.egg.ylt.Utils.DateUtils;
import com.egg.ylt.Utils.StatusBarUtil;
import com.egg.ylt.Utils.StringUtil;
import com.egg.ylt.adapter.ADA_ViewPagerAdapter;
import com.egg.ylt.fragment.FRA_SelectTime;
import com.egg.ylt.viewpagertabindicator.TabPagerIndicator;
import com.yonyou.framework.library.base.BaseActivity;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ACT_SelectTime extends BaseActivity {

    @BindView(R.id.include_iv_back)
    ImageView includeIvBack;
    @BindView(R.id.include_tv_title)
    TextView includeTvTitle;
    @BindView(R.id.include_tv_right)
    TextView includeTvRight;
    @BindView(R.id.include_rl_view)
    RelativeLayout includeRlView;
    @BindView(R.id.pagerIndicator)
    TabPagerIndicator pagerIndicator;
    @BindView(R.id.viewPager)
    ViewPager viewPager;


    private ArrayList<Fragment> mFragments;
    private int mPosition;
    public static String serviceId;

    @Override
    protected void getBundleExtras(Bundle extras) {
        serviceId = extras.getString("serviceId");
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_select_time;
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void initViewsAndEvents() {

        StatusBarUtil.setStatusBarColor(this, R.color.ylt_whit);
        StatusBarUtil.StatusBarLightMode(this);
        //动态设置沉浸式状态栏的高度
        CustomUtils.setImmersiveStatusBar(mContext, includeRlView);

        //设置title
        includeTvTitle.setText("预约到店时间");
        initData();
        initTabLayout();
    }

    private void initTabLayout() {

    }

    private void initData() {
        List<String> titles = DateUtils.get7date1();
        mFragments = new ArrayList<>();
        for (int i = 0; i < titles.size(); i++) {
            mFragments.add(FRA_SelectTime.newInstance(i));
        }

        ADA_ViewPagerAdapter pagerAdapter = new ADA_ViewPagerAdapter(getSupportFragmentManager(), mFragments, titles);
        viewPager.setAdapter(pagerAdapter);
        pagerIndicator.setViewPager(viewPager);

        //设置viewpager的监听事件
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mPosition = position;
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    public void showBusinessError(ErrorBean error) {

    }

    @OnClick({R.id.include_iv_back, R.id.tv_sure_time})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.include_iv_back://返回键
                finish();
                break;
            case R.id.tv_sure_time://确定选中时间
                FRA_SelectTime fra_selectTime = (FRA_SelectTime) mFragments.get(mPosition);
//                String teacherId = fra_selectTime.getTeacherIde();
//                String teacherName = fra_selectTime.getTeacherName();
                if (StringUtil.isEmpty(fra_selectTime.getSelectedTime())) {
                    ToastUtil.makeText(mContext, "请选择时间", false);
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra("time", fra_selectTime.getSelectedTime());
//                intent.putExtra("teacherId", teacherId);
//                intent.putExtra("teacherName", teacherName);
                setResult(Constants.SELECT_SERVICE_TIME, intent);
                finish();
                break;
        }
    }
}
